import { createRouter, createWebHistory } from "vue-router";
import login from "../view/loginMain.vue";
import mainpage from "../view/mainPage.vue";
import password from "../view/PassWord.vue";
import system from "../view/viewSystem.vue";
import infor from "../view/inFor.vue";
import role from "../view/viewRole.vue";
import custom from "../view/viewCustom.vue"
import contract from '../view/viewContract.vue'
import data from "../view/viewData.vue"
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/login",
      name: "login",
      component: login,
    },
    {
      path: "/mainpage",
      name: "mainpage",
      component: mainpage,
      children: [
        {
          path: "password",
          component: password,
        },
        {
          path: "system",
          component: system,
        },
        {
          path: "infor",
          component: infor,
        },
        {
          path: "role",
          component: role,
        },
        {
          path: "custom",
          component: custom,
        },
        {
          path:"contract",
          component:contract
        },
        {
          path:"data",
          component:data
        },
        
      ],
    },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../view/')
    // }
    {
      path: "/",
      redirect: "/login",
    },
  ],
});
router.beforeEach((to) => {
  if (to.name !== "login" && !sessionStorage.login) {
    return { name: "login" };
  }
});
export default router;
